package com.example;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class User1 implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean {
    private String name;

    public User1() {
        System.out.println("step 1：实例化Bean【构造方法】");
    }

    public void setName(String name) {
        this.name = name;
        System.out.println("step 2：设置属性的值:" + name + "【setter方法】");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("step 3：执行BeanNameAware接口规定的setBeanName()方法：" + name);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("step 4：执行BeanFactoryAware接口规定的setBeanFactory()方法");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("step 5：执行ApplicationContextAware接口规定的setApplicationContext()方法");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("step 7：执行InitializingBean接口规定的afterPropertiesSet()方法");
    }

    public void init_method() {
        System.out.println("step 8：执行Bean的init_method()【在xml中配置】");
    }

    public void destroy_method() {
        System.out.println("step 11：执行Bean的destroy_method()【在xml中配置】");
    }

}
